
<template>
  <div class="app-container">
    <!-- 查询表单 -->
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="80px">

            <el-form-item label="园区编码" prop="parkAreaCode">
              <el-input
                v-model="queryParams.parkAreaCode"
                placeholder="请输入园区编码"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="园区名称" prop="parkAreaName">
              <el-input
                v-model="queryParams.parkAreaName"
                placeholder="请输入园区名称"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="公司名称" prop="companyName">
              <el-input
                v-model="queryParams.companyName"
                placeholder="请输入公司名称"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="联系人" prop="contactName">
              <el-input
                v-model="queryParams.contactName"
                placeholder="请输入联系人"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="联系电话" prop="contactPhone">
              <el-input
                v-model="queryParams.contactPhone"
                placeholder="请输入联系电话"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="备用字段1" prop="parkAreaBackup1">
              <el-input
                v-model="queryParams.parkAreaBackup1"
                placeholder="请输入备用字段1"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="备用字段2" prop="parkAreaBackup2">
              <el-input
                v-model="queryParams.parkAreaBackup2"
                placeholder="请输入备用字段2"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="备用字段3" prop="parkAreaBackup3">
              <el-input
                v-model="queryParams.parkAreaBackup3"
                placeholder="请输入备用字段3"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="备用字段4" prop="parkAreaBackup4">
              <el-input
                v-model="queryParams.parkAreaBackup4"
                placeholder="请输入备用字段4"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="备用字段5" prop="parkAreaBackup5">
              <el-input
                v-model="queryParams.parkAreaBackup5"
                placeholder="请输入备用字段5"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="创建者ID" prop="createId">
              <el-input
                v-model="queryParams.createId"
                placeholder="请输入创建者ID"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="创建者姓名" prop="createName">
              <el-input
                v-model="queryParams.createName"
                placeholder="请输入创建者姓名"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="创建时间" prop="createTime">
              <el-input
                v-model="queryParams.createTime"
                placeholder="请输入创建时间"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="更新者ID" prop="updateId">
              <el-input
                v-model="queryParams.updateId"
                placeholder="请输入更新者ID"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="更新者姓名" prop="updateName">
              <el-input
                v-model="queryParams.updateName"
                placeholder="请输入更新者姓名"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="更新时间" prop="updateTime">
              <el-input
                v-model="queryParams.updateTime"
                placeholder="请输入更新时间"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
            <el-form-item label="账户ID" prop="accountId">
              <el-input
                v-model="queryParams.accountId"
                placeholder="请输入账户ID"
                clearable
                @keyup.enter.native="handleQuery"
              />
            </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <!-- 操作按钮 -->
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['business:parkAreaInfo:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['business:parkAreaInfo:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['business:parkAreaInfo:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['business:parkAreaInfo:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <!-- 数据表格 -->
    <el-table v-loading="loading" :data="parkAreaInfoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
            <el-table-column label="园区编码" align="center" prop="parkAreaCode" />
            <el-table-column label="园区名称" align="center" prop="parkAreaName" />
            <el-table-column label="公司名称" align="center" prop="companyName" />
            <el-table-column label="联系人" align="center" prop="contactName" />
            <el-table-column label="联系电话" align="center" prop="contactPhone" />
            <el-table-column label="备用字段1" align="center" prop="parkAreaBackup1" />
            <el-table-column label="备用字段2" align="center" prop="parkAreaBackup2" />
            <el-table-column label="备用字段3" align="center" prop="parkAreaBackup3" />
            <el-table-column label="备用字段4" align="center" prop="parkAreaBackup4" />
            <el-table-column label="备用字段5" align="center" prop="parkAreaBackup5" />
            <el-table-column label="创建者ID" align="center" prop="createId" />
            <el-table-column label="创建者姓名" align="center" prop="createName" />
            <el-table-column label="更新者ID" align="center" prop="updateId" />
            <el-table-column label="更新者姓名" align="center" prop="updateName" />
            <el-table-column label="账户ID" align="center" prop="accountId" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['business:parkAreaInfo:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['business:parkAreaInfo:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 分页组件 -->
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
                <el-form-item label="园区编码" prop="parkAreaCode">
                  <el-input v-model="form.parkAreaCode" placeholder="请输入园区编码" />
                </el-form-item>
                <el-form-item label="园区名称" prop="parkAreaName">
                  <el-input v-model="form.parkAreaName" placeholder="请输入园区名称" />
                </el-form-item>
                <el-form-item label="公司名称" prop="companyName">
                  <el-input v-model="form.companyName" placeholder="请输入公司名称" />
                </el-form-item>
                <el-form-item label="联系人" prop="contactName">
                  <el-input v-model="form.contactName" placeholder="请输入联系人" />
                </el-form-item>
                <el-form-item label="联系电话" prop="contactPhone">
                  <el-input v-model="form.contactPhone" placeholder="请输入联系电话" />
                </el-form-item>
                <el-form-item label="备用字段1" prop="parkAreaBackup1">
                  <el-input v-model="form.parkAreaBackup1" placeholder="请输入备用字段1" />
                </el-form-item>
                <el-form-item label="备用字段2" prop="parkAreaBackup2">
                  <el-input v-model="form.parkAreaBackup2" placeholder="请输入备用字段2" />
                </el-form-item>
                <el-form-item label="备用字段3" prop="parkAreaBackup3">
                  <el-input v-model="form.parkAreaBackup3" placeholder="请输入备用字段3" />
                </el-form-item>
                <el-form-item label="备用字段4" prop="parkAreaBackup4">
                  <el-input v-model="form.parkAreaBackup4" placeholder="请输入备用字段4" />
                </el-form-item>
                <el-form-item label="备用字段5" prop="parkAreaBackup5">
                  <el-input v-model="form.parkAreaBackup5" placeholder="请输入备用字段5" />
                </el-form-item>
                <el-form-item label="创建者ID" prop="createId">
                  <el-input v-model="form.createId" placeholder="请输入创建者ID" />
                </el-form-item>
                <el-form-item label="创建者姓名" prop="createName">
                  <el-input v-model="form.createName" placeholder="请输入创建者姓名" />
                </el-form-item>
                <el-form-item label="创建时间" prop="createTime">
                  <el-input v-model="form.createTime" placeholder="请输入创建时间" />
                </el-form-item>
                <el-form-item label="更新者ID" prop="updateId">
                  <el-input v-model="form.updateId" placeholder="请输入更新者ID" />
                </el-form-item>
                <el-form-item label="更新者姓名" prop="updateName">
                  <el-input v-model="form.updateName" placeholder="请输入更新者姓名" />
                </el-form-item>
                <el-form-item label="更新时间" prop="updateTime">
                  <el-input v-model="form.updateTime" placeholder="请输入更新时间" />
                </el-form-item>
                <el-form-item label="账户ID" prop="accountId">
                  <el-input v-model="form.accountId" placeholder="请输入账户ID" />
                </el-form-item>
      </el-form>
              <div slot="footer" class="dialog-footer" align = "center">
          <el-button type="primary" @click="submitForm">确 定</el-button>
          <el-button @click="cancel">取 消</el-button>
        </div>
    </el-dialog>
  </div>
</template>

<script>
import { listParkAreaInfo, getParkAreaInfo, delParkAreaInfo, addParkAreaInfo, updateParkAreaInfo } from "@/api/business/parkAreaInfo";

export default {
  name: "parkAreaInfo",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 业务表格数据
      parkAreaInfoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
            parkAreaCode: null,
            parkAreaName: null,
            companyName: null,
            contactName: null,
            contactPhone: null,
            parkAreaBackup1: null,
            parkAreaBackup2: null,
            parkAreaBackup3: null,
            parkAreaBackup4: null,
            parkAreaBackup5: null,
            createId: null,
            createName: null,
            updateId: null,
            updateName: null,
            accountId: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
            parkAreaCode: [
              { required: true, message: "园区编码不能为空", trigger:"blur" }
            ],
            parkAreaName: [
              { required: true, message: "园区名称不能为空", trigger:"blur" }
            ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询业务列表 */
    getList() {
      this.loading = true;
      debugger
      listParkAreaInfo(this.queryParams).then(response => {
        this.parkAreaInfoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
            id: null,
            parkAreaCode: null,
            parkAreaName: null,
            companyName: null,
            contactName: null,
            contactPhone: null,
            parkAreaBackup1: null,
            parkAreaBackup2: null,
            parkAreaBackup3: null,
            parkAreaBackup4: null,
            parkAreaBackup5: null,
            createId: null,
            createName: null,
            createTime: null,
            updateId: null,
            updateName: null,
            updateTime: null,
            accountId: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
        /** 重置按钮操作 */
        resetQuery() {
          this.resetForm("queryForm");
          this.handleQuery();
        },
        // 多选框选中数据
        handleSelectionChange(selection) {
          let pkField = "";
              pkField = "id";
          this.ids = selection.map(item => item[pkField])
          this.single = selection.length!== 1
          this.multiple =!selection.length
        },
        /** 新增按钮操作 */
        handleAdd() {
          this.reset();
          this.open = true;
          this.title = "添加业务";
        },
        /** 修改按钮操作 */
        handleUpdate(row) {
          this.reset();
          let pkField = "";
              pkField = "id";
          const id = row[pkField] || this.ids
          getParkAreaInfo(id).then(response => {
            this.form = response.data;
            this.open = true;
            this.title = "修改业务";
          });
        },
        /** 提交按钮 */
        submitForm() {
          this.$refs["form"].validate(valid => {
            if (valid) {
              let pkField = "";
                  pkField = "id";
              if (this.form[pkField]!= null) {
                updateParkAreaInfo(this.form).then(response => {
                  this.$modal.msgSuccess("修改成功");
                  this.open = false;
                  this.getList();
                });
              } else {
                addParkAreaInfo(this.form).then(response => {
                  this.$modal.msgSuccess("新增成功");
                  this.open = false;
                  this.getList();
                });
              }
            }
          });
        },
        /** 删除按钮操作 */
        handleDelete(row) {
          let pkField = "";
              pkField = "id";
          const ids = row[pkField] || this.ids;
          this.$modal.confirm('是否确认删除业务编号为"' + ids + '"的数据项？').then(() => {
            return delParkAreaInfo(ids);
          }).then(() => {
            this.getList();
            this.$modal.msgSuccess("删除成功");
          }).catch(() => {});
        },
        /** 导出按钮操作 */
        handleExport() {
          this.download('business/parkAreaInfo/export', {
            ...this.queryParams
          }, 'parkAreaInfo_' + new Date().getTime() + '.xlsx');
        }
      }
    };
    </script>
